package com.agile.leetcode.hutool.file.filewatcher;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.watch.SimpleWatcher;
import cn.hutool.core.io.watch.WatchMonitor;
import org.junit.Test;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.WatchEvent;

/**
 * @Author KD
 * @Date 2021/1/7 15:30
 */
public class FileWatcherDemo {
    public static void main(String[] args) {
        // 创建文件
        File file = FileUtil.file("D:\\czk\\hutool\\watcher\\czk.txt");
        // 监听全部时间
        WatchMonitor.createAll(file, new SimpleWatcher() {
            @Override
            public void onModify(WatchEvent<?> event, Path currentPath) {
                System.out.println("event modify");
                System.out.println(currentPath.getFileName());
                System.out.println(event.count());
            }
        }).start();
    }
    @Test
    public void test1(){

    }
}
